package com.leetcode.algorithm.y22.m09.w2;

/**
 * 1221. 分割平衡字符串
 * 
 * https://leetcode.cn/problems/split-a-string-in-balanced-strings/
 * 
 * @author jie.deng
 *
 */
class Question1221Solution01 {

	public int balancedStringSplit(String s) {
		int cnt = 0;
		int cntL = 0;
		int cntR = 0;
		int idx = 0;
		int len = s.length();
		while (idx < len) {
			if (s.charAt(idx) == 'L') {
				cntL++;
			} else {
				cntR++;
			}
			if (cntL == cntR) {
				cnt++;
				cntL = 0;
				cntR = 0;
			}
			idx++;
		}
		return cnt;
	}

}